#!/bin/bash

allowable="txt c cpp cxx h hpp hxx txx"

tmpfile="tmp18042312727527890997aapnootmies.txt"

# For all files
for file in $*
do
	# Check if they exist, is a regular file, readable and writable.
	if [ -f $file ] && [ -r $file ] && [ -w $file ] #&& [ ! -x $file ]
	then
		# Check if the extension is of allowed type
		# to make sure we are not parsing binary files.
		ext=${file##*.}
		allowed="false"
		for allow in $allowable
		do
			if [[ "$ext" == "$allow" ]]
			then
				allowed="true"
			fi
		done
		# Do remove trailing spaces
		if [[ "$allowed" == "true" ]]
		then
			echo $file
      sed 's/[ \t]*$//' $file &> $tmpfile
			mv $tmpfile $file
		fi
	fi
done

exit
